package com.github.permissiondog.cancanpbackend.servlet;

import com.github.permissiondog.cancanpbackend.model.Role;
import com.github.permissiondog.cancanpbackend.request.ApproverRequest;
import com.github.permissiondog.cancanpbackend.response.ApproverResponse;
import com.github.permissiondog.cancanpbackend.response.ApproversResponse;
import com.github.permissiondog.cancanpbackend.response.BaseResponse;
import com.github.permissiondog.cancanpbackend.service.TemplateService;
import com.github.permissiondog.cancanpbackend.service.UserService;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/template/approver")
public class ApproverServlet extends BaseServlet {
    /**
     * 获取审批人列表
     */
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException {
        int templateId;
        try {
            templateId = Integer.parseInt(req.getParameter("templateId"));
        } catch (Exception e) {
            json(res, BaseResponse.builder().ok(false).msg("参数错误").build());
            return;
        }

        var approvers = TemplateService.getInstance().getApprovers(templateId);
        json(res, ApproversResponse.builder().ok(true).approver(approvers).build());
    }
}
